<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.id"
          clearable
          placeholder="搜索患者姓名"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.patientName"
          clearable
          placeholder="诊所名称"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.gender"
          clearable
          placeholder="所属集团"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.parent"
          clearable
          placeholder="销售"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.parentMobile"
          clearable
          placeholder="省份"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.doctorId"
          clearable
          placeholder="城市"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.clinicId"
          clearable
          placeholder="套餐类型"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="矫治器类型"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="牙模类型"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="诊疗状态"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.clinicId"
          clearable
          placeholder="诊疗阶段"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="搜索患者编号"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="主治医生"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="区域"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.clinicId"
          clearable
          placeholder="诊疗阶段"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="诊所性质"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="提交资料时间"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="牙模收到时间"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.clinicId"
          clearable
          placeholder="报告上传时间"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="患者状态"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="报告诊断结果"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.deptId"
          clearable
          placeholder="报告状态"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <rrOperation :crud="crud"></rrOperation>
        <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
        <crudOperation :permission="permission"></crudOperation>
      </div>
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="500px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="ID">
            <el-input v-model="form.id" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="form.patientName" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-radio v-for="item in dict.gender" :key="item.id" v-model="form.gender" :label="item.value">
              {{ item.label }}</el-radio>
          </el-form-item>
          <el-form-item label="出生日期">
            <el-date-picker v-model="form.birthDay" type="datetime" style="width: 370px;"></el-date-picker>
          </el-form-item>
          <el-form-item label="家长姓名">
            <el-input v-model="form.parent" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="家长联系方式">
            <el-input v-model="form.parentMobile" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="form.createDate" type="datetime" style="width: 370px;"></el-date-picker>
          </el-form-item>
          <el-form-item label="主管医生ID，参考 t_doctor">
            <el-input v-model="form.doctorId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="诊所ID">
            <el-input v-model="form.clinicId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="所属部门">
            <el-input v-model="form.deptId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="是否标星收藏，0未收藏，1已收藏">
            <el-input v-model="form.star" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="患者头像URL">
            <el-input v-model="form.photoUrl" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="产品规则">
            <el-input v-model="form.productRuleId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="套餐规则">
            <el-input v-model="form.packageRuleId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="是否已归档 0 未归档 1 已归档 已归档普通查询不可见">
            <el-input v-model="form.archived" style="width: 370px;"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        stripe
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" sortable label="所属区域" width="120"></el-table-column>
        <el-table-column prop="deptId" sortable label="所属销售" width="120"></el-table-column>
        <!-- <el-table-column prop="deptId" sortable label="诊所省份" width="120"/> -->
        <el-table-column prop="clinicId" sortable label="诊所名称" width="120">

          <template slot-scope="scope">
            {{ dict.label.patient_parent_rel[scope.row.clinicId] }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="deptId" sortable label="所属集团" width="120"/> -->
        <!-- <el-table-column prop="deptId" sortable label="诊所性质" width="120"/> -->
        <!-- <el-table-column prop="deptId" sortable label="患者姓名" width="120"/> -->
        <!-- <el-table-column prop="deptId" sortable label="患者编号" width="120"/> -->
        <el-table-column prop="createDate" sortable label="创建时间" width="140">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="gender" sortable label="患者性别" width="120">
          <template slot-scope="scope">
            {{ dict.label.gender[scope.row.gender] }}
          </template>
        </el-table-column>
        <!-- ID，参考 t_doctor -->
        <el-table-column prop="doctorId" sortable label="主管医生" width="120"></el-table-column>
        <el-table-column prop="birthDay" sortable label="出生日期" width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.birthDay) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="parent" sortable label="家长姓名" width="120"></el-table-column>
        <!-- <el-table-column prop="relationship" sortable label="家长关系" width="120">
          <template slot-scope="scope">
            {{ dict.label.patient_parent_rel[scope.row.relationship] }}
          </template>
        </el-table-column>
        <el-table-column prop="relationship" sortable label="物流状态" width="120">
          <template slot-scope="scope">
            {{ dict.label.dictDetails[scope.row.relationship] }}
          </template>
        </el-table-column>
        <el-table-column prop="parentProfession" sortable label="家长职业" />
        <el-table-column prop="parentMobile" sortable label="家长联系方式" />
        <el-table-column prop="orthodonticHis" sortable label="家长正畸史" />
        <el-table-column prop="doctorId" sortable label="主管医生ID，参考 t_doctor" />
        <el-table-column prop="clinicId" sortable label="诊所ID" />
        <el-table-column prop="deptId" sortable label="所属部门" />
        <el-table-column prop="tags" sortable label="标签" />
        <el-table-column prop="star" sortable label="是否标星收藏，0未收藏，1已收藏" />
        <el-table-column prop="photoUrl" sortable label="患者头像URL" />
        <el-table-column prop="productRuleId" sortable label="产品规则" />
        <el-table-column prop="packageRuleId" sortable label="套餐规则" />
        <el-table-column prop="archived" sortable label="是否已归档 0 未归档 1 已归档 已归档普通查询不可见">
          <template slot-scope="scope">
            {{ dict.label.patient_archive[scope.row.archived] }}
          </template>
        </el-table-column> -->
        <el-table-column v-permission="['admin','oper:patient:edit']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission"></udOperation>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination></pagination>
    </div>
  </div>
</template>

<script>
import crudPatient from '@/api/patient';
import CRUD, { presenter, header, form, crud } from '@crud/crud';
import rrOperation from '@crud/RR.operation';
import crudOperation from '@crud/CRUD.operation';
import udOperation from '@crud/UD.operation';
import pagination from '@crud/Pagination';

const defaultForm = {
  id: null,
  patientName: null,
  gender: null,
  birthDay: null,
  compliance: null,
  parent: null,
  relationship: null,
  parentProfession: null,
  parentMobile: null,
  orthodonticHis: null,
  createDate: null,
  doctorId: null,
  clinicId: null,
  deptId: null,
  tags: null,
  star: null,
  photoUrl: null,
  productRuleId: null,
  packageRuleId: null,
  archived: null
};
export default {
  name: 'Patient',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['gender', 'dictDetails', 'patient_parent_rel', 'patient_archive'],
  cruds() {
    return CRUD({
      title: 'PatientService',
      url: '/patient/queryPage',
      sort: 'id,desc',
      crudMethod: { ...crudPatient },
      props: { searchToggle: true },
      optShow: {
        add: false,
        edit: true,
        del: true,
        download: true,
        reset: true
      }
    });
  },
  data() {
    return {
      permission: {
        add: ['admin', 'patient:add'],
        edit: ['admin', 'oper:patient:edit'],
        del: ['admin', 'patient:del']
      },
      rules: {},
      queryTypeOptions: [
        { key: 'id', display_name: 'ID' },
        { key: 'patientName', display_name: '姓名' },
        { key: 'gender', display_name: '性别' },
        { key: 'parent', display_name: '家长姓名' },
        { key: 'parentMobile', display_name: '家长联系方式' },
        { key: 'doctorId', display_name: '主管医生ID，参考 t_doctor' },
        { key: 'clinicId', display_name: '诊所ID' },
        { key: 'deptId', display_name: '所属部门' }
      ]
    };
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true;
    }
  }
};
</script>

<style scoped>
</style>
